package com.example.design.strategy;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: Bin.L
 * @date: 2022/3/12 17:39
 * @Description:
 */
public class ExecuteMain {

    // 策略上下文，用于管理策略的注册和获取
    private static final Map<String, AwardStrategy> registerMap = new HashMap<>();

    // 注册策略
    public static void registerStrategy(String rewardType, AwardStrategy strategy) {
        registerMap.putIfAbsent(rewardType, strategy);
    }

    // 获取策略
    public static AwardStrategy getStrategy(String rewardType) {
        return registerMap.get(rewardType);
    }

    public static void main(String[] args) {
        // 初始化具体策略 - 有Spring环境 可以利用Spring的Bean机制来代替
        Waimai.getInstance();
        Hotel.getInstance();
        Food.getInstance();

        AwardStrategy strategy = getStrategy("Food");
        strategy.issue("This is a param...");
    }

}
